package com.walter.condition;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class BaseCondition extends SpringBootCondition {

    private final WebApplicationType webApplicationType;

    protected BaseCondition(WebApplicationType webApplicationType) {
        this.webApplicationType = webApplicationType;
    }

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConditionMessage.Builder message = ConditionMessage.forCondition("NONE Condition");

        switch(webApplicationType) {
            case NONE:
                return ConditionOutcome.match("Right Condition");
            case SERVLET:
                return ConditionOutcome.noMatch(message.found("invalid SERVLET property").atAll());
            case REACTIVE:
                return ConditionOutcome.noMatch(message.found("invalid REACTIVE property").atAll());
            default:
                return null;
        }
    }
}
